package com.aij.ims.handler;

import com.aij.ims.entity.Message;
import com.aij.starter.service.LlmService.LLMCallback;
import com.alibaba.fastjson.JSON;

import io.netty.channel.Channel;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

/**
 * LLM回调处理
 */
public class LlmHandler implements LLMCallback {

	private Message msg;
	private Channel channel;
	
	public LlmHandler(Message msg, Channel channel) {
		this.msg = msg;
		this.channel = channel;
	}
	
	public void run(String message) {
        try {
    		msg.params.body = message;
    		message = JSON.toJSONString(msg);
            //遍历出所有连接的通道
            //for (Channel channel : ChatHandler.clients) {
                //推送给指定的通道
                channel.writeAndFlush(new TextWebSocketFrame(message));
            //}
        } catch (Exception e) {
        	System.out.println(e.getMessage() + "\n" + e.getStackTrace());
        }
	}

}
